package com.zqh.apiorderquery.controller;

import com.zqh.apiorderquery.redis.RedisUtil;
import com.zqh.myfmmall.clients.OrderQueryClient;
import com.zqh.myfmmall.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description :
 * @Author :kono淇杭哒、
 * @Create 2022-03-05 23:00
 */
@RestController
@RequestMapping("order/query")

public class ApiOrderQueryController{
    /**
     * 服务对象
     */
    @Autowired
    private OrderQueryClient orderQueryClient;
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private RedisUtil redisUtil;

    @GetMapping("pageByStatus/{pageNum}/{pageSize}/{status}")
    public Result pageByStatus (@PathVariable("pageNum") Integer pageNum,
                 @PathVariable("pageSize") Integer pageSize,
                 @PathVariable("status") Integer status){
        String token = request.getHeader("token");
        String uId = (String) redisUtil.get(token);
        return orderQueryClient.pageByStatus(pageNum,pageSize,status,uId);
    }

    @GetMapping("counts")
    public Result counts(){
        String token = request.getHeader("token");
        String uId = (String) redisUtil.get(token);
        return orderQueryClient.counts(uId);
    }
}
